/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import request from '@/utils/request';
import { isLegalData } from '@/utils/utils';
import { isArray } from 'lodash';

// 获取同城订单
export async function approved(params) {
  return request('/Api/YZ/CourierStation/checkDak', {
    method: 'POST',
    body: params,
  });
}
// 下属驿站充值列表
export async function chargePostList(params) {
  return request('/Api/YZ/CourierStation/chargePosts', {
    method: 'POST',
    body: params,
  });
}

// 区域内驿站，驿站详情
export async function getPostInfo(params) {
  return request('/Api/ChinaPost/Dak/subDakInfo', {
    method: 'POST',
    body: params,
  });
}
// 下属驿站充值短信、可消费余额
export async function charging(params) {
  return request('/Api/InnAccount/batchRecharge', {
    method: 'POST',
    body: params,
  });
}
// 下属驿站充值结果查询
export async function getChargingResult(params) {
  return request('/Api/InnAccount/queryRechargeResult', {
    method: 'POST',
    body: params,
  });
}

// 区域内驿站，修改驿站经营信息
export async function modifyPostInfo(params) {
  return request('/Api/YZ/CourierStation/modifyPostInfo', {
    method: 'POST',
    body: params,
  });
}

// 下属驿站，获取中邮下属驿站列表
export async function getZyAccountList(params) {
  return request('/Api/ChinaPost/Dak/getAccountList', {
    method: 'POST',
    body: params,
  });
}
// 下属驿站，获取片区列表
export async function getZoneList(params) {
  return new Promise(resolve => {
    request('/Api/Site/getAreaSiteListByPhone', {
      method: 'POST',
      body: params,
    })
      .then((res = {}) => {
        const { code, data = [] } = res;
        if (code == 0) {
          isArray(data) &&
            data.forEach(element => {
              element.site_id = `${element.site_id}`;
            });
          resolve(data);
        } else {
          resolve([]);
        }
      })
      .catch(() => {
        resolve([]);
      });
  });
}
// 下属驿站，开启驿站片区管理或者共配片区管理的片区列表
export async function getGpYzZoneList(params) {
  return new Promise(resolve => {
    request('/Api/Site/getAreaSiteList', {
      method: 'POST',
      body: params,
    })
      .then((res = {}) => {
        const { code, data = [] } = res;
        if (code == 0) {
          resolve(isLegalData(data));
        } else {
          resolve([]);
        }
      })
      .catch(() => {
        resolve([]);
      });
  });
}

// 下属驿站，片区分配
export async function zoneDispatch(params) {
  return request('/Api/Site/divideInnAreaPower', {
    method: 'POST',
    body: params,
  });
}

// 下属驿站，获取所有已开启驿站片区管理的片区
export async function getInnZoneList(params) {
  return new Promise(resolve => {
    request('/Api/Site/getInnAreaSiteList', {
      method: 'POST',
      body: params,
    })
      .then((res = {}) => {
        const { code, data = [] } = res;
        if (code == 0) {
          resolve(isLegalData(data));
        } else {
          resolve([]);
        }
      })
      .catch(() => {
        resolve([]);
      });
  });
}
